package com.xz.design.patterns.observer;

import java.util.ArrayList;
import java.util.List;
// 公众号
public class SubScriptionSubject implements Subject {

    // 定义一个集合，用来观察多个观察者对象
    private List<Observer> weixinUserList = new ArrayList<Observer>();

    @Override
    public void attach(Observer server) {
        weixinUserList.add(server);
    }

    @Override
    public void detach(Observer server) {
        weixinUserList.remove(server);
    }

    @Override
    public void notify(String message) {
        for (Observer observer : weixinUserList) {
            observer.update(message);
        }
    }
}
